//
//  FCVehicleRealTimeStatueDetailView.m
//  ZhuKuang
//
//  Created by mafy on 17/7/12.
//  Copyright © 2017年 jjkj. All rights reserved.
//

#import "FCVehicleRealTimeStatueDetailView.h"
#import "YZDetailTableView.h"
#import "FCVehicleIolAndCurveController.h"//车辆油耗与速度曲线
#import "FCVehicleReamTimeStatusModel.h"

@interface FCVehicleRealTimeStatueDetailView()

@property (nonatomic, strong) UIView *backGroungView;//白色背景

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic,strong) UIButton *closeBtn;//关闭按钮

@property (nonatomic, strong) UIButton *optionBtn;//车辆曲线按钮

@property (nonatomic, strong) YZDetailTableView *tableView;//详情列表

@end

@implementation FCVehicleRealTimeStatueDetailView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
       
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        
        [self addSubview:self.backGroungView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.closeBtn];
        [self addSubview:self.optionBtn];
        [self addSubview:self.tableView];
        
        [self setSubViewsFrame];
    }
    
    return self;
}

#pragma mark - 车辆曲线按钮
- (void)optionButtonClick:(UIButton *)sender{
    
    //车辆油耗与速度曲线页面
    FCVehicleIolAndCurveController *vehicleIolAndCurveVC = [[FCVehicleIolAndCurveController alloc]init];
    [self.viewController.navigationController pushViewController:vehicleIolAndCurveVC animated:YES];
}

#pragma mark - 关闭按钮监听
- (void)closeButtonClick:(UIButton *)sender{
    
    [self setHidden:YES];
}

#pragma mark - 设置数据源
- (void)setModel:(FCVehicleReamTimeStatusModel *)model{
    _model = model;
    
    self.tableView.currentColor = COLOR(25, 158, 216, 1);
    
    NSArray *titleArray = @[@"卡车",@"类别",@"部门",@"时间",@"司机",@"油量",@"坐标"];
    NSMutableArray *contentArray = [NSMutableArray array];
    
    //卡车
    [contentArray addObject:model.carNum];
    //类别
    [contentArray addObject:model.type];
    //部门
    [contentArray addObject:model.unit];
    //时间
    NSString *time = [LZXHelper getTimeStrWithOldDateFomatter:@"YYYY-MM-dd HH:mm:ss" DateStr:model.ServerTime newFormatter:@"YYYY-MM-dd HH:mm"];
    [contentArray addObject:time];
    //司机
    [contentArray addObject:model.driver];
    //油量
    NSString *iol = [NSString stringWithFormat:@"%.1fL",[model.iol floatValue]];
    [contentArray addObject:iol];
    //坐标
    [contentArray addObject:model.point];
    
    self.tableView.titleArray = titleArray;
    self.tableView.contentArray = contentArray;
}

#pragma mark - 布局
- (void)setSubViewsFrame{
    
    [self.backGroungView  mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.mas_left).with.offset(15);
        make.right.mas_equalTo(self.mas_right).with.offset(-15);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.height.mas_equalTo(@536);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.backGroungView.mas_top).with.offset(15);
        make.centerX.mas_equalTo(self.backGroungView.mas_centerX);
        make.height.mas_equalTo(@21);
    }];
    
    [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.backGroungView.mas_bottom).with.offset(-15);
        make.centerX.mas_equalTo(self.backGroungView.mas_centerX).with.offset(-75);
        make.width.mas_equalTo(@90);
        make.height.mas_equalTo(@35);
    }];
    
    [self.optionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.backGroungView.mas_bottom).with.offset(-15);
        //        make.centerX.mas_equalTo(self.backGroungView.mas_centerX).with.offset(-65);
        make.left.mas_equalTo(self.closeBtn.mas_right).with.offset(20);
        make.width.mas_equalTo(@135);
        make.height.mas_equalTo(@35);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.titleLabel.mas_bottom).with.offset(40);
        make.left.mas_equalTo(self.backGroungView.mas_left).with.offset(15);
        make.right.mas_equalTo(self.backGroungView.mas_right).with.offset(-15);
        make.bottom.mas_equalTo(self.closeBtn.mas_top).with.offset(-20);
    }];
}

#pragma mark - 懒加载
- (YZDetailTableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[YZDetailTableView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
    }
    
    return _tableView;
}

- (UIButton *)optionBtn{
    
    if (!_optionBtn) {
        
        _optionBtn = [[UIButton alloc]init];
        [_optionBtn setTitle:@"车辆曲线" forState:UIControlStateNormal];
        [_optionBtn setBackgroundColor:COLOR(25, 158, 216, 1)];
        _optionBtn.titleLabel.font = [UIFont systemFontOfSize:16.0f];
        [_optionBtn addTarget:self action:@selector(optionButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _optionBtn.layer.cornerRadius = 4.0f;
        _optionBtn.layer.masksToBounds = YES;
    }
    
    return _optionBtn;
}

- (UIButton *)closeBtn{
    
    if (!_closeBtn) {
        
        _closeBtn = [[UIButton alloc]init];
        [_closeBtn setTitle:@"关闭" forState:UIControlStateNormal];
        [_closeBtn setBackgroundColor:COLOR(25, 158, 216, 1)];
        _closeBtn.titleLabel.font = [UIFont systemFontOfSize:16.0f];
        [_closeBtn addTarget:self action:@selector(closeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _closeBtn.layer.cornerRadius = 4.0f;
        _closeBtn.layer.masksToBounds = YES;
    }
    
    return _closeBtn;
}

- (UILabel *)titleLabel{
    
    if (!_titleLabel) {
        
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"车辆在线/离线详情";
        _titleLabel.font = [UIFont systemFontOfSize:18.0f];
        _titleLabel.textColor = COLOR(0, 153, 204, 1);
        _titleLabel.frame = CGRectMake(0, 64, kScreenWidth, 44);
        _titleLabel.backgroundColor = [UIColor whiteColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    return _titleLabel;
}

- (UIView *)backGroungView{
    
    if (!_backGroungView) {
        
        _backGroungView = [[UIView alloc]init];
        _backGroungView.backgroundColor = [UIColor whiteColor];
    }
    
    return _backGroungView;
}

@end
